<?php
/**
 * 用户发送短信
 * User: csyr
 * Date: 16/7/10
 * Time: 下午8:53
 */

namespace Common\Library;


use Think\Cache\Driver\Redis;
use Think\Log;

class CacheRedis {

    const PREFIX_KEY = 'MaibeiCache::';
    const UID = 'maibei_cache';

    const TYPE_CACHE_CODE = 'review_notify';

    public static function setKey($key, $type)
    {
        $redis = new Redis();
        $cacheKey = self::PREFIX_KEY . self::TYPE_CACHE_CODE . ':' . $key . ':' . $type;

        $cacheResult = $redis->get($cacheKey);
        if (!$cacheResult) {
            if (false === $redis->set($cacheKey, $key)) {
                Log::write('缓存审核通知失败：$key:' . $key . ' $type:' . $type, Log::INFO);
            }
        }

        Log::write('缓存审核写入：$key:' . $key . ' $type:' . $type, Log::INFO);

        return true;
    }

    public static function getKey($key, $type) {
        $redis = new Redis();
        $cacheKey = self::PREFIX_KEY . self::TYPE_CACHE_CODE . ':' . $key . ':' . $type;

        Log::write('缓存审核获取：$key:' . $key . ' $type:' . $type, Log::INFO);

        return $redis->get($cacheKey);
    }

    public static function removeKey($key, $type) {
        $redis = new Redis();
        $cacheKey = self::PREFIX_KEY . self::TYPE_CACHE_CODE . ':' . $key . ':' . $type;

        Log::write('缓存审核删除：$key:' . $key . ' $type:' . $type, Log::INFO);
        return $redis->rm($cacheKey);
    }
}
